<template>

</template>
<script>
import md5 from 'crypto-js/md5';
export default {
        data(){
            return{
                modal1: false,
                modal2: false,
                module:'users',
                list: [],
                filter:{
                    page:1,
                    total:0,
                    limit:5,
                    name:''
                },
                ids:[]
            }
        },
         methods: {
            show (index) {
                this.$Modal.info({
                    title: '用户信息',
                    content: `姓名：${this.list[index].name}<br>年龄：${this.list[index].age}<br>邮箱：${this.list[index].email}`
                })
            },
            remove (index) {
                this.list.splice(index, 1);
            },
            getSelected(selection,row){
                // console.log(row)
                this.ids.push(row._id)
                console.log(this.ids)
            },
            cancelSelected(selection,row){
                var aIds=this.ids;
                alert(this.ids.length)
                for(var i=0;i<aIds.length;i++){
                    if(aIds[i]==row._id){
                        aIds.splice(i,1)
                        this.ids=aIds
                        console.log(this.ids)
                    }
                }
            },
            handleSelectAll (status) {
                this.$refs.selection.selectAll(status);
                // for(var i=0;i<){}
            },
            selectA(selection){
                alert(1);
                for(var i=0;i<selection.length;i++){
                    // alert(1)
                   this.ids[i]=selection[i]._id
                }
            },
            removeSelected(){
                this.$Modal.confirm({
                    title: '确认删除数据吗?',
                    content: '请确认是否删除该记录！',
                    onOk: () => {
                        this.axios({
                                url: `http://10.31.155.74:3000/${this.module}/data/removes`,
                                data: {
                                    ids: this.ids.toString()
                                },
                                method: 'post'
                            }).then(res=>{
                                this.getDate();
                        })
                    }
                });

            },
            getDate(){
                this.axios({
                    url:`http://10.31.155.74:3000/${this.module}/list`,
                    method:'post',
                    // data:this.filter
                }).then((res)=>{
                    console.log(res)
                    this.list=res.data.rows;
                    this.filter.total=res.data.total;
                    this.filter.limit = res.data.limit;
                    // console.log(res.data)
                })
            },
            ok () {
                // console.log(this.name)
                if(this.name&&this.age&&this.email&&this.password){
                    this.axios({
                        url:`http://10.31.155.74:3000/${this.module}/data`,
                        method:'post',
                        data:{
                            name:this.name,
                            age:this.age,
                            email:this.email,
                            password:md5(this.password).toString(),
                            info:this.info,
                        }
                    }).then(res=>{
                        this.$Message.info('添加成功');
                        this.getDate();
                        this.name=null;
                        this.age=null;
                        this.email=null;
                        this.password=null;
                        this.info=null;
                    })
                }else{
                    this.$Message.info('添加失败');
                }




            },
            cancel () {
                this.$Message.info('取消添加');
            },
            cok () {
                // console.log(this.name)
                if(this.cname&&this.cage&&this.cemail&&this.cpassword){
                    this.axios({
                        url:`http://10.31.155.74:3000/${this.module}/data/${this.changeId}`,
                        method:'put',
                        data:{
                            name:this.cname,
                            age:this.cage,
                            email:this.cemail,
                            password:md5(this.cpassword).toString(),
                        }
                    }).then(res=>{
                        this.$Message.info('修改成功');
                        this.getDate();
                    })
                }else{
                    this.$Message.info('修改失败');
                }




            },
            ccancel () {
                this.$Message.info('取消修改');
            },
            addUser(){
                this.modal1 = true;
            },
            changePage(page){
                this.filter.page=page;
                this.getDate();
            },
            changeLimit(limit){
                this.filter.limit=limit;
                this.getDate();
            },
            search(){
                this.getDate();
            }
         }

    }

</script>
